<template>
	<view>
		<view class="navStyle">
			<u-navbar :is-back="false" z-index=999 title="" :background="background">
				<view class="slot-wrap" @tap="goBack">
					<u-icon name="close" margin-left="30rpx" label="主题详情" label-size="50" color="#000000" size="40"></u-icon>
				</view>
				
			</u-navbar>
		</view>
		<!-- <view v-for="(item, index) in commentValue" :key="index"> -->
			<u-card>
				<view class="headStyle" slot="head">{{comment.questionTitle}}</view>
				<view class="bodyStyle" slot="body">
					<view class="u-body-item u-flex u-col-between u-p-t-0">
						<view class="u-body-item-title contentStyle">{{comment.questionContent}}</view>
					</view>
				</view>
				<view class="u-line-1" slot="foot">
					<u-icon name="chat-fill" size="30" color="" :label="comment.replyTimes" label-size="20" color="#4169E1" style="margin-left: 10rpx;"></u-icon><text
					 style="margin-left: 170rpx;font-size: 20rpx;color: #F29100;">{{comment.releaseTime}}</text><text style="margin-left: 150rpx;font-size: 20rpx;color: #19BE6B;">{{comment.userName}}</text>
				</view>
			</u-card>
		<!-- </view> -->
		<view>
			<button class="buttonStyle" type="primary" @tap="goReply">回复</button>
		</view>
		<view v-for="(item, index) in replys" class="cardStyle" :key="index">
			<u-card :title="item.userName" :sub-title="item.replyTime">
				<view class="replyStyle" slot="body">
					<view class="u-body-item u-flex u-col-between u-p-t-0">
						<view class="u-body-item-title contentStyle">{{item.answerContent}}</view>
					</view>
				</view>
			</u-card>
		</view>
	</view>
</template>

<script>
	import {
		getReply
	} from '@/api/modules/commentarea.js'
	export default {
		data() {
			return {
				courseID:1,
				//吸顶背景色
				background: {
					backgroundColor: '#F3F4F6',
					backgroundImage: 'linear-gradient(45deg,#c2e9fb,#a1c4fd)'
				},
				//单个评论
				comment:{},
				//主题 
				replys: [],
				//回复,这里要在数据库获取，通过问题的id
				comments: [],
			};
		},
		methods: {
			goReply() {
					uni.navigateTo({
					// 传字符串太长会断了，所以要编码才可以
					url: 'commentReply?id=' + this.comment.id + '&title=' + this.comment.title,
				})
			},
			goBack(){
				let that = this
				that.courseID = uni.getStorageSync('courseID')
				// uni.navigateTo({
				// 	url: '../courseDetails?courseID='+this.courseID,
				// 	fail(){
				// 	uni.navigateBack(1)
				// }
				// })
				uni.navigateBack(1)
			}
		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			let that = this
			that.replys = uni.getStorageSync('replys')
		},
		mounted() {
/* 			let that = this
			that.comment    = uni.getStorageSync('comment')
			let replyTimes = ""
			replyTimes = uni.getStorageSync('replyTimes')
			if(replyTimes!= ""){
				that.comment.replyTimes = uni.getStorageSync('replyTimes')
				//console.log("显示的评论数量"+that.comment.replyTimes)
				uni.removeStorageSync('replyTimes')
			}
			let courseDetails = {
				commentId: uni.getStorageSync('questionId')
			};
			getReply(courseDetails)
				.then(resp => {
					this.replys = resp.data.replylist;
					uni.setStorageSync('replys', this.replys)
				})
				.catch(resp => {})
			that.replys = uni.getStorageSync('replys') */
		},
		onShow() {
			let that = this
			that.comment    = uni.getStorageSync('comment')
			let replyTimes = ""
			replyTimes = uni.getStorageSync('replyTimes')
			if(replyTimes!= ""){
				that.comment.replyTimes = uni.getStorageSync('replyTimes')
				//console.log("显示的评论数量"+that.comment.replyTimes)
				uni.removeStorageSync('replyTimes')
			}
			let courseDetails = {
				commentId: uni.getStorageSync('questionId')
			};
			getReply(courseDetails)
				.then(resp => {
					this.replys = resp.data.replylist;
					uni.setStorageSync('replys', this.replys)
				})
				.catch(resp => {})
			that.replys = uni.getStorageSync('replys')
		}
	};
</script>

<style scoped lang="scss">
	.u-card-wrap {
		background-color: $u-bg-color;
		padding: 1px;
	}

	.u-body-item {
		font-size: 32rpx;
		color: #333;
		padding: 20rpx 10rpx;
	}

	.u-body-item image {
		width: 120rpx;
		flex: 0 0 120rpx;
		height: 120rpx;
		border-radius: 8rpx;
		margin-left: 12rpx;
	}

	.headStyle {
		font-size: 35rpx;
		font-weight: bold;

	}
	.navStyle {
		display: block;
		background-color: #F29100;
		z-index: 999;
	}
.slot-wrap {
		display: flex;
		align-items: center;
		margin-left: 30rpx;

		/* 如果您想让slot内容占满整个导航栏的宽度 */
		/* flex: 1; */
		/* 如果您想让slot内容与导航栏左右有空隙 */
		/* padding: 0 30rpx; */
	}
	.contentStyle {
		margin-top: 30rpx;
		font-size: 30rpx;
	}

	.replyStyle {
		font-size: 15rpx;
	}

	.cardStyle {
		margin-bottom: 80rpx;
	}

	.buttonStyle {
		background-color: #18B566;
		position: fixed;
		bottom: 0rpx;
		width: 100%;
		display: block;
		z-index: 999;
	}
</style>
